// Project: Salient
// http://salient.codeplex.com
// 
// Copyright 2010, Sky Sanders <sky at skysanders.net>
// Dual licensed under the MIT or GPL Version 2 licenses.
// http://salient.codeplex.com/license
// 
// Date: April 25 2010 

#region

using System.Web.Script.Serialization;

#endregion

namespace Salient.Web.Security
{
    ///<summary>
    ///</summary>
    public class AccessControlHeader
    {
        private static readonly JavaScriptSerializer Js = new JavaScriptSerializer();
        ///<summary>
        ///</summary>
        public bool authenticated;
        ///<summary>
        ///</summary>
        public bool loginResult;
        ///<summary>
        ///</summary>
        public bool logout;

        ///<summary>
        ///</summary>
        public AccessControlMode mode = AccessControlMode.none;
        ///<summary>
        ///</summary>
        public string password;
        ///<summary>
        ///</summary>
        public string path;
        ///<summary>
        ///</summary>
        public string rawUrl;
        ///<summary>
        ///</summary>
        public string requestType;
        ///<summary>
        ///</summary>
        public bool unauthenticated;

        ///<summary>
        ///</summary>
        public string username;

        ///<summary>
        ///</summary>
        ///<returns></returns>
        public string ToJSON()
        {
            return Js.Serialize(this);
        }

        ///<summary>
        ///</summary>
        ///<param name="value"></param>
        ///<returns></returns>
        public static AccessControlHeader FromJSON(string value)
        {
            try
            {
                if (string.IsNullOrEmpty(value))
                {
                    return new AccessControlHeader();
                }
                return Js.Deserialize<AccessControlHeader>(value);
            }
            catch
            {
                return new AccessControlHeader();
            }
        }
    }
}